/*
 * Copyright (c) 2010-2013 Ruben Chakhmakhchyan. All rights reserved.
 * 
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Eclipse Public License
 * Version 1.0 (the 'License'). You may not use this file except in
 * compliance with the License. Please obtain a copy of the License at
 * http://opensource.org/licenses/EPL-1.0 and read it before using this file.
 */

#pragma once

#include "commontypes.h"
#include <stdio.h>


#define PDF_FILE_BUFFER 10000000


class PdfStream abstract
{
public:

    virtual ~PdfStream() { }

    virtual void write( byte_t* data, uint_t size ) = 0;
    virtual void writeByte( byte_t data ) = 0;
    virtual uint_t getPosition() = 0;
};

class PdfMemoryStream : public PdfStream
{
private:

    byte_t* m_buffer;	// binary buffer
    uint_t m_sp;		// stream position

public:

    PdfMemoryStream( uint_t bufferSize );

    virtual ~PdfMemoryStream();

    uint_t getBufferSize() { return PDF_FILE_BUFFER; }
    uint_t getSize() { return m_sp; } // stream is incremental

    virtual void write( byte_t* data, uint_t size );
    virtual void writeByte( byte_t data );
    virtual uint_t getPosition() { return m_sp; }

    void saveToFile( char* filename );
    unsigned int getData( void** data );
};


class PdfFileStream : public PdfStream
{
private:

    FILE* m_handle;		// stream handle
    uint_t m_sp;		// stream position

public:

    PdfFileStream( wchar_t* filename );

    virtual ~PdfFileStream();

    uint_t getBufferSize() { return PDF_FILE_BUFFER; }
    uint_t getSize() { return m_sp; } // stream is incremental

    virtual void write( byte_t* data, uint_t size );
    virtual void writeByte( byte_t data );
    virtual uint_t getPosition() { return m_sp; }
};
